package com.kyxx.topics.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kyxx.topics.R;
import com.kyxx.topics.bean.TagBean;
import com.kyxx.topics.widget.HeaderViewPagerFragment;

import java.util.List;

/**
 * Created by lt on 2015/12/14.
 */
public class MainTabFragmentAdapter extends FragmentPagerAdapter {

    private final List<TagBean> titles;
    private Context context;
    private List<HeaderViewPagerFragment> fragments;

    public MainTabFragmentAdapter(List<HeaderViewPagerFragment> fragments, List<TagBean> titles, FragmentManager fm, Context context) {
        super(fm);
        this.context = context;
        this.fragments = fragments;
        this.titles = titles;
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return titles.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position).getTitle();
    }

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_main_tab, null);
        TextView tv = (TextView) view.findViewById(R.id.tv_tab);
        ImageView iv_tab_point = (ImageView) view.findViewById(R.id.iv_tab_point);
        tv.setText(titles.get(position).getTitle());
        return view;
    }
}
